package com.yida.gwj.basis.controller.common;

import com.yida.common.core.exception.ServiceException;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.gwj.basis.domain.request.GwjInitApiRequest;
import com.yida.gwj.basis.service.IGwjInitApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 小区基础数据初始化（基础数据管理模块）Controller
 *
 * @author lqq
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/api")
public class GwjInitApiController extends BaseController {

	@Autowired
	private IGwjInitApiService apiService;

	/**
	 * 拉取楼栋信息
	 */
	@GetMapping("/getCommunity")
	public AjaxResult getCommunity(@Validated GwjInitApiRequest request) {
		return AjaxResult.success(apiService.getCommunity(request));
	}

	/**
	 * 拉取楼栋信息
	 */
	@GetMapping("/getBuild")
	public AjaxResult getBuild(@Validated GwjInitApiRequest request) {
		if (StringUtils.isBlank(request.getProjectCode()) && StringUtils.isBlank(request.getBuildCode())) {
			throw new ServiceException("请求参数不全");
		}
		return AjaxResult.success(apiService.getBuild(request));
	}

	/**
	 * 拉取房屋信息
	 */
	@GetMapping("/getHouse")
	public AjaxResult getHouse(@Validated GwjInitApiRequest request) {
		return AjaxResult.success(apiService.getHouse(request));
	}

	/**
	 * 拉取业主信息
	 */
	@GetMapping("/getOwner")
	public AjaxResult getOwner(@Validated GwjInitApiRequest request) {
		return AjaxResult.success(apiService.getOwner(request));
	}
}
